package com.yyc.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.yyc.pojo.TblUser;
import com.yyc.service.UserService;

@Controller
@RequestMapping("/user")
public class UserController {
	
	@Autowired
	private UserService userService;
	
	@RequestMapping("/selectUser")
	public String selectUser(ModelMap model){
		List<TblUser> user = userService.selectAllUser();
		model.addAttribute("user", user);
		return "user/user";
	}
	
	@RequestMapping("/addUser")
	public String addUser(){
		return "user/addUser";
	}
	
	@RequestMapping("/addUserSuccess")
	public String addUserSuccess(HttpServletRequest request){
		TblUser user = new TblUser();
		user.setUsername(request.getParameter("username"));
		user.setPassword(request.getParameter("password"));
		user.setRealname(request.getParameter("realname"));
		user.setPhone(request.getParameter("phone"));
		user.setEmail(request.getParameter("email"));
		userService.addUser(user);
		return "redirect:selectUser";
	}

}
